use ggez::mint::Point2;
use noise::{NoiseFn, Perlin};

pub struct Walker {
    location: Point2<f64>,
    tstep: f64,
}

impl Walker {
    pub fn new(location: Point2<f64>) -> Walker{
        Walker{location : location, tstep: 0.0}
    }
    pub fn get_location(& self) -> Point2<f64> {
        self.location
    }
    pub fn move_to(&mut self, target: Point2<f64>) {
        let perlin = Perlin::new(0);

        let step = perlin.get([self.tstep, 1.0])*4.0+4.0;

        self.tstep += 0.0221;

        let direction_x = target.x-self.location.x;
        let direction_y = target.y-self.location.y;
        let norm_x = direction_x/(direction_x*direction_x + direction_y*direction_y).sqrt();
        let norm_y = direction_y/(direction_x*direction_x + direction_y*direction_y).sqrt();
        self.location.x += norm_x*step;
        self.location.y += norm_y*step;
    }
}
